﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace WebSite.HttpModule
{
    /// <summary>
    /// when a client was login,it should go to different page or has different rights
    /// do something when access application in LoginHttpModule
    /// </summary>
    public class LoginHttpModule : IHttpModule
    {
        public LoginHttpModule()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #region IHttpModule Members

        public void Dispose()
        {

        }

        public void Init(HttpApplication context)
        {
            context.AcquireRequestState += new EventHandler(context_AcquireRequestState);
        }

        #endregion

        private void context_AcquireRequestState(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;
            if (context.Session["IsLogin"] != null && context.Session["IsLogin"] == "YES")
            {
                context.Response.Redirect("Default.aspx");
            }
            else
            {
                context.Response.Redirect("Login.aspx");
            }
        }
    }
}
